using Gtk;
using GLib;
using Posix;

public class ShopWindow : Gtk.ApplicationWindow {

	Gtk.Entry entry_price;
	Gtk.Entry entry_quantity;
	Gtk.ComboBoxText combobox;

	public ShopWindow(Gtk.Application app, string title) {
	
		Object(application : app, title : title);
		
		var builder = new Gtk.Builder();
		
		try{
		
			builder.add_from_file(@"$(Constants.DATADIR)/$(Constants.RELEASE_NAME)/main.ui");
			
			builder.connect_signals(this);
		
			combobox = builder.get_object("comboboxtext1") as Gtk.ComboBoxText;
		
			combobox.set_active(0);
		
			this.entry_price = builder.get_object("entry_price") as Gtk.Entry;
		
			this.entry_quantity = builder.get_object("entry_quantity") as Gtk.Entry;
		
			this.set_position(WindowPosition.CENTER);
		
			this.add(builder.get_object("grid_main") as Gtk.Widget);
			
		} catch (GLib.Error e) {
		
			GLib.message(e.message);
			
			Posix.exit(0);
		}
	}
	
	public void calc_result() {
	
		double price = double.parse(this.entry_price.get_text());
		
		int quantity = int.parse(entry_quantity.text);
		
		var cashier = new Cashier(combobox.get_active_text());
		
		message("Result = %f", cashier.get_result(price * quantity));
	}
}

public class Shop : Gtk.Application {

	protected override void activate() {
	
		new ShopWindow(this, "Matrix's Super Shop").show();
		
		return;
	}

	static int main(string args[]) {
	
		var shop = new Shop();
	
		return shop.run(args);
	}
}
